package com.sunlg.smarthome.ui.personal;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.sunlg.smarthome.R;
import com.sunlg.smarthome.data.entity.Notification;

import java.util.List;

/**
 * Created by sunlg on 2017/5/31.
 */

public class NotificationAdapter extends RecyclerView.Adapter {

    private Context context;
    private List<Notification> notifications;

    public NotificationAdapter(Context context, List<Notification> notifications) {
        this.context = context;
        this.notifications = notifications;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(context).inflate(R.layout.item_notification, parent, false);

        return new ItemViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ItemViewHolder viewHolder = (ItemViewHolder)holder;
        Notification notification = notifications.get(position);
        viewHolder.tvContent.setText(notification.getTitle());
        viewHolder.tvContent.setText(notification.getContent());
        viewHolder.tvTime.setText(notification.getTime());
    }

    @Override
    public int getItemCount() {
        return notifications.size();
    }

    private static class ItemViewHolder extends RecyclerView.ViewHolder{

        private TextView tvTitle;
        private TextView tvContent;
        private TextView tvTime;

        public ItemViewHolder(View itemView) {
            super(itemView);

            tvTitle = (TextView)itemView.findViewById(R.id.tv_title);
            tvContent = (TextView)itemView.findViewById(R.id.tv_content);
            tvTime = (TextView)itemView.findViewById(R.id.tv_time);

        }
    }
}
